package com.smscenter.server.core.ems;

import com.smscenter.server.core.IExecutor;
import com.zeus.base.smscenter.common.constant.EmsConstants;
import com.zeus.base.smscenter.common.constant.SmsConstants;
import com.zeus.base.smscenter.common.security.MD5;
import com.zeus.base.smscenter.common.util.WebUtils;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016-02-17.
 */
public class EmsExecutor implements IExecutor {

	public static void main(String[] args) throws IOException {
		
		EmsExecutor w = new EmsExecutor();
		Map map = new HashMap();
		map.put("loginName", "fyrjgstc");
		map.put("loginPassword", MD5.generate("82557339",false).toLowerCase());
		map.put("phone", "15504607909");
		map.put("content", "订单发货喽123!");
		map.put("bizNo", "4383080");
		System.out.println(w.excute(map));;
	}
	
    public String excute(Map<String, Object> params) throws IOException {
        String bizNo = (String) params.get("bizNo");//唯一ID
        String enterpriseID=(String) params.get("enterpriseID");//	企业ID
        String loginName = (String) params.get("loginName");//用户名
        String loginPassword = (String) params.get("loginPassword");//密码
        String subPort = (String) params.get("smsId");//	扩展端口
        String phone = (String) params.get("phone");//电话号
        String content = (String) params.get("content");//内容
        String sendTime	= (String) params.get("sendTime");//定时发送时间

        Map<String,String> requestMap=new HashMap<String, String>();

        requestMap.put("enterpriseID",enterpriseID==null ? EmsConstants.ENTERPRISEID :enterpriseID );
        requestMap.put("loginName",loginName);
        requestMap.put("password",loginPassword);
        requestMap.put("smsId",bizNo);
        requestMap.put("subPort",subPort);
        requestMap.put("content",content);
        requestMap.put("mobiles",phone);
        requestMap.put("sendTime",sendTime);

        String rsp = WebUtils.doPost(EmsConstants.SMS_URL,WebUtils.buildAllQuery(requestMap, SmsConstants.CHARSET_UTF8), SmsConstants.CHARSET_UTF8, 10000, 10000);
        return rsp;
    }
}
